<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<?php
    if(!isset($_SESSION['id'])){
        echo"<script>alert('you have to log back in to continue');</script>";
        header("Location: Logout.php");
      
    }

include("db.php");
    $id=$_GET['id'];
    if($_SERVER['REQUEST_METHOD']=="POST"){
        $sql="UPDATE`basket` SET `ProductName`=?, `Amount`=?, `Price`=?,`ProductImage`=? WHERE id=?";
        $stmt=mysqli_stmt_init($conn);
        mysqli_stmt_prepare($stmt,$sql);
        mysqli_stmt_bind_param($stmt,"sidss",$name,$amount,$price,$image,$id);
        if(!mysqli_stmt_execute($stmt)){
            die("ERROR" .mysqli_stmt_error($stmt));
        }
        else{
            echo"<script>alert('Item Updated added to basket');</script>";
            mysqli_stmt_close($stmt);
        }
    }

    $sql="SELECT`ProductName`, `ProductImage`, `ProductPrice`, `ProductDescription`,`CompanyName` FROM `Products` WHERE Product_id = ?";
    $stmt=mysqli_stmt_init($conn);
    mysqli_stmt_prepare($stmt,$sql);
    mysqli_stmt_bind_param($stmt,"i",$id);
    if(mysqli_stmt_execute($stmt)){
        $result=mysqli_stmt_get_result($stmt);
        $row=mysqli_fetch_assoc($result);
    }
?>
    
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">

    <title>Account creation</title>
</head>
<style>
    .pill-navbar{
        border-radius: 50px;  
        padding:10px 20px;
        
    }
    @media(max-width:900px){
        
        .pill-navbar{
        border-radius: 25px;  
        margin-top:10px;

        }
        .pill-navbar .collapse-navbar{
            margin-top:10px;
            padding-top:10px;
            border-top:1px#eee
        }
    }
    .card{
        min-width:70vw;
        min-height:40vh;
        border-radius: 40px;  
        padding: 50px;
        max-height:80vh;
        overflow-y:auto;
    }

   
    .button{
        min-height:5vh;
        max-height:5vh;
    }

    body{

        background-image: linear-gradient(rgba(0,0,0,0.2),rgba(0,0,0,0.7)), url("Dark-theme.jpg");
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        min-height:100vh;
      
    }
    .form-group{
        margin-bottom:1rem;
    }

</style>
<body>
    
  
    
    
    <!-- navbar -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light shadow pill-navbar w-50 mx-auto my-4 mb-5  ">
    
        <a class="navbar-brand" href="#">Logo</a>

        <!-- expand/collapse button -->
        <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#Navbar">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- nav links -->
        <div class="collapse navbar-collapse ms-4" id="Navbar">
            <ul class="navbar-nav mt-auto">
                <li class="nav-item"><a class="nav-link" href="">Products</a></li>
                <li class="nav-item"><a class="nav-link" href="">Suppliers</a></li>
                <li class="nav-item"><a class="nav-link" href="">Orders</a></li>
                <li class="nav-item"><a class="nav-link" href="">Loyalty</a></li>
            </ul>
            <!-- right side nav links -->
            <ul class="navbar-nav ms-auto ">
                <li class="nav-item"><a class="nav-link" href="">Log out<span class="bi bi-person-fill"></span></a></li>
                <li class="nav-item"><a class="nav-link" href="">Settings<span class="bi bi-gear-fill"></span></a></li>
            </ul>
        </div>

    </nav>

    
    
    <!-- main content -->
   <div class="container p-auto mt-5 ">
        <div class="col-lg-12 mx-auto mt-5">
            <a href="CustomerProducts.php"><--Go Back</a>
            <div class="card">
                <div class="header">
                    <div class="card-title text-center" style="padding-left:9rem; padding-right:9rem;">  
                        <h3><?php echo htmlspecialchars($row['Company name'])?></h3>
                </div>
                <div class="card-body px-auto mt-3">
                    <div class="card-text px-auto">
                        <div class="row">

                            <div class="col-lg-5" style="min-height:60vh;">
                                
                                <img class="col-12-lg border center mx-auto my-5" style="min-height:400px; max-width:400px;" src="<?php echo htmlspecialchars($row['ProductImage'])?>" alt="Image not available" /> 
                            
                            </div>

                            <div class="col-lg-7">
                                <div class="col-12-lg border my-5 p-4" style="min-height:500px;">
                                    <form action="ProducerEditItems.php" method="post">

                                        <div class="form-group">
                                            <label for="fname">Producer name</label>
                                            <input class="form-control" type="text" name="Product_name"  value="<?php echo htmlspecialchars($row['ProductName'])?>"  placeholder="<?php echo htmlspecialchars($row['ProductName'])?>">
                                        </div>

                                       
                                        <div class="form-group">
                                            <label for="desc" class="form-label">Description</label>
                                            <textarea class="form-control"  name="desc" rows="5" placeholder="<?php echo htmlspecialchars($row['ProductPrice'])?>" disabled></textarea>
                                        </div>

                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <label for="amount" class="form-label">amount</label>
                                                    <input class="form-control form-control-small" type="number" name="amount">
                                                </div>

                                                <div class="col-lg-6">
                                                    <label for="price" class="form-label">price</label>
                                                    <textarea class="form-control form-control-small"  name="price" value="<?php echo htmlspecialchars($row['Price'])?>" placeholder="<?php echo htmlspecialchars($row['Price'])?>"></textarea>
                                                </div>
                                            </div>
    
                                        </div>
                                        <input type="text" name="image" value="<?php echo htmlspecialchars($row['ProductImage'])?>">
                                        <button class="btn btn-primary"  type="submit"><h5>add to basket</h5></button>
                                    </form>
                                    
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
            

        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
